package com.wk.service.impl;

import com.wk.service.UploadService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Service
public class UploadServiceImpl implements UploadService {
    @Override
    public String upload(MultipartFile picture, HttpServletRequest request) {

        String originalFilename = null;

        originalFilename = picture.getOriginalFilename();

        originalFilename = new Date().getTime()+""+originalFilename;

        String realPath = request.getServletContext().getRealPath("/img");

        try{
            picture.transferTo(new File(realPath+"/"+originalFilename));
        }catch(Exception e){
            e.printStackTrace();
            originalFilename = null;
        }

        return originalFilename;
    }
}
